package com.homework;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author xiyu
 * @version 1.0
 * @date 2025/3/29 20:49
 * @description
 */
public class T6 {
    public static void main(String[] args) {
        File dir = new File("D:\\file\\test");
        File[] files = dir.listFiles();
        System.out.println("文件名/目录名\t    修改时间\t\t\t    文件类型\t 大小（只有标准文件显示）");
        for (File file : files) {
            System.out.print(file.getName()+"\t    ");

            long mod = file.lastModified();
            Date date = new Date(mod);
            String pattern = "yyyy/MM/dd HH:mm:ss";
            SimpleDateFormat sdf = new SimpleDateFormat(pattern);
            String t2 = sdf.format(date);
            System.out.print(t2+"\t\t\t    ");

            if (file.isDirectory()){
                System.out.print("目录\t ");
                System.out.println();
            }else {
                System.out.print(file.getName().substring(file.getName().indexOf('.')+1)+"文件\t ");
                if (file.length()/1024==0){
                    System.out.println("1kb");
                }else {
                    System.out.println(file.length()/1024+"kb");
                }
            }


        }
    }
}
